package cn.study.aviplayer;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ConfigurationInfo;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;

import java.io.File;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    static {
        System.loadLibrary("avi-lib");
        System.loadLibrary("native-lib");
    }

    private EditText fileNameEdit;

    private RadioGroup playerRadioGroup;

    private Button playButton;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fileNameEdit = findViewById(R.id.file_name_edit);
        playerRadioGroup = findViewById(R.id.player_radio_group);
        playButton = findViewById(R.id.play_button);

        playButton.setOnClickListener(this);

        //查看opengl es 的版本
        ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = am.getDeviceConfigurationInfo();
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.play_button:

                onPlayButtonClick();
                break;
        }

    }

    private void onPlayButtonClick() {

        Intent intent = null;
        int radioId = playerRadioGroup.getCheckedRadioButtonId();
        switch (radioId) {

            case R.id.bitmap_player_radio:

                intent = new Intent(this, BitmapPlayerActivity.class);
                break;
            case R.id.open_gl_player_radio:

                intent = new Intent(this, OpenGLPlayerActivity.class);
                break;

            case R.id.native_window_player_radio:

                intent = new Intent(this, NativeWindowPlayerActivity.class);
                break;

            default:
                throw new UnsupportedOperationException("radioId=" + radioId);
        }
        File file = new File(getExternalFilesDir(null).getAbsoluteFile(), fileNameEdit.getText().toString());

        intent.putExtra(AbstractPlayerActivity.EXTRA_FILE_NAME, file.getAbsolutePath());
        startActivity(intent);
    }
}
